﻿using UnityEngine;

[ExecuteInEditMode, ImageEffectAllowedInSceneView]
public class OilPaintEffect : MonoBehaviour
{
    private Material mat;
    //两个参数值
    [Range(0, 5), Tooltip("分辨率比例值")]
    public float ResolutionValue = 0.9f;
    [Range(1, 30), Tooltip("半径的值，决定了迭代的次数")]
    public int RadiusValue = 5;

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (mat == null)
        {
            mat = new Material(Shader.Find("Custom/OilPaint"));
        }

        mat.SetFloat("_ResolutionValue", ResolutionValue);
        mat.SetInt("_Radius", RadiusValue);
        mat.SetVector("_ScreenResolution", new Vector4(source.width, source.height, 0.0f, 0.0f));

        Graphics.Blit(source, destination, mat);
    }
}
